package com.spzx.user.controller;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spzx.common.core.domain.R;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.user.domain.UserAddress;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.annotation.Resource;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.user.service.IUserAddressService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 用户地址Controller
 *
 * @author atguigu
 * @date 2024-07-10
 */
@Tag(name = "用户地址接口管理")
@RestController
@RequestMapping("/userAddress")
public class UserAddressController extends BaseController {


    @Autowired
    private IUserAddressService iUserAddressService;

    @Operation(summary = "查询用户地址列表")
    @RequiresLogin
    @GetMapping("/list")
    public AjaxResult list(){
        List<UserAddress> userAddresseList = iUserAddressService.getAddressList();
        return success(userAddresseList);
    }
    /**
     * 新增用户地址
     */
    @Operation(summary = "新增用户地址")
    @RequiresLogin
    @PostMapping()
    public AjaxResult addUserAddress(@RequestBody UserAddress userAddress){
        iUserAddressService.addUserAddress(userAddress);
        return success();
    }

    /**
     * 修改用户地址
     */
    @Operation(summary = "修改用户地址")
    //@RequiresLogin
    @PutMapping()
    private AjaxResult updateUserAddress(@RequestBody UserAddress userAddress){
        iUserAddressService.updateUserAddress(userAddress);
        return success();
    }


    /**
     * 删除用户地址
     */
    @Operation(summary = "删除用户地址")
    @RequiresLogin
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Integer id){
        QueryWrapper<UserAddress> userAddressQueryWrapper = new QueryWrapper<>();
        userAddressQueryWrapper.eq("id", id);
        iUserAddressService.remove(userAddressQueryWrapper);
        return success();
    }

    @Operation(summary = "获得用户地址信息")
    @GetMapping("/getUserAddress/{id}")
    public R<UserAddress> getUserAddress(@PathVariable Long id){
        UserAddress userAddress = iUserAddressService.getById(id);
        return R.ok(userAddress);
    }


}
